﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace SolutionCrapFinder
{
    [Serializable]
    public class SCFProjectSettings
    {
        // members
        [XmlElement(ElementName = "directory")]
        public string m_directory = "";
        [XmlElement(ElementName = "solutions")]
        public List<string> m_solutions = new List<string>();
        [XmlElement(ElementName = "ignoredfiles")]
        public HashSet<string> m_ignoredFiles = new HashSet<string>();

        [NonSerialized]
        public bool m_IsDirty = false;

        public SCFProjectSettings() { }

        public static SCFProjectSettings Load(string fileName)
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(SCFProjectSettings));
            using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return (SCFProjectSettings)xmlFormat.Deserialize(fStream);
            }
        }

        public static void Save(string fileName, SCFProjectSettings obj)
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(SCFProjectSettings));
            using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                xmlFormat.Serialize(fStream, obj);
            }
        }

        public void Clear()
        {
            m_directory = "";
            m_solutions.Clear();
        }
    }
}
